package site.yunnong.atvris.admin.service.impl;

import org.springframework.stereotype.Service;
import site.yunnong.atvris.dao.admin.service.SysVideoManageService;
import site.yunnong.atvris.dao.common.exception.YunnongException;
import site.yunnong.atvris.dao.common.util.LocalAssert;
import site.yunnong.atvris.dao.mapper.CmsVideoMapper;
import site.yunnong.atvris.dao.model.CmsVideo;

import javax.annotation.Resource;

/**
 * @author zjh
 * @date 2021/6/30 23:32
 */
@Service
public class SysVideoManageServiceImpl implements SysVideoManageService {

    @Resource
    private CmsVideoMapper cmsVideoMapper;

    @Override
    public int changeVideoPermission(Long id, Integer status) {
        CmsVideo cmsVideo = cmsVideoMapper.selectByPrimaryKey(id);
        LocalAssert.notNull(cmsVideo, "不存在该视频");
        if (status.equals(cmsVideo.getStatus())) {
            throw new YunnongException("该视频已处于目标状态");
        }
        cmsVideo.setStatus(status);
        return cmsVideoMapper.updateByPrimaryKey(cmsVideo);
    }
}
